package com.youlu.campus.web.common.utils;

import java.util.Random;
import java.util.UUID;

/**
 * 表id生成工具
 *
 * @author pdjt
 */
public class IdGenerator {

    public static String generateId() {
        return UUID.randomUUID().toString().replace("-", "").toLowerCase();
    }

    /**
     * 商品编号
     * @return
     */
    public static String generateGoodsNo(String prefix){
        StringBuilder sbl = new StringBuilder();
        sbl.append(prefix).append(DateTimeUtils.getDate()).append(getRandNum(1,9999));
        return sbl.toString();
    }

    public static int getRandNum(int min, int max) {
        int randNum = min + (int)(Math.random() * ((max - min) + 1));
        return randNum;
    }


    public static String createOrderNo() {
        int machineId = 1;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if(hashCodeV < 0) {//有可能是负数
            hashCodeV = - hashCodeV;
        }
        // 0 代表前面补充0
        // 4 代表长度为4
        // d 代表参数为正数型
        return machineId+String.format("%015d", hashCodeV);
    }


    private static int random(int begin,int end){

        Random rand = new Random();
        int randNumber =rand.nextInt(end - begin + 1) + begin;
        return randNumber;
    }
    
    public static void main(String[] args) {
        System.out.println(random(1,2));

    }


}
